// DebugLog.h: Debug Extension code
//
// Contians C Debug code
/*******************************************************************
//		*** COPYRIGHT NOTICE ****
//
//	Copyright 2003. David Maisonave (david@axter.com)
//	
//	This code is free for use under the following conditions:
//
//		You may not claim authorship of this code.
//		You may not sell or distrubute this code without author's permission.
//		You can use this code for your applications as you see fit, but this code may not be sold in any form
//		to others for use in their applications.
//		This copyright notice may not be removed.
//
//
//  No guarantees or warranties are expressed or implied. 
//	This code may contain bugs.
*******************************************************************/
//  Please let me know of any bugs, bug fixes, or enhancements made to this code.
//  If you have ideas for this, and/or tips or admonitions, I would be glad to hear them.
//
//////////////////////////////////////////////////////////////////////

#ifndef DEBUGLOG_H_HEADER_GAURD_
#define DEBUGLOG_H_HEADER_GAURD_ 1

//Global misc defines
#define USE_HTML_SCREEN_CODE_



#define DEBUG__MODE_ 1  /*Comment this out for release version*/

/*The above line will get modified when Project configuration is changed from Release version to Debug (and V.S.)*/

#define DEBUGLOG_TRACEALLFUNCCALLS_ON
/*****************************************************************************/
/*                   F U N C T I O N     P R O T O T Y P E S                 */
/*****************************************************************************/
/* Debug function prototypes (DM 17/11/2003                                  */
#if defined(DEBUG__MODE_) && !defined(DEBUGLOG_DISABLE_FOR_THIS_SRC)
/* Release version will **NOT** include these functions                      */
void DosBeep__(int, int);  //Use this wrapper function so that bsedos.h doesn't have to be pulled in the debug header file
void DebugOut(const char far * gf_Filename, int gf_LineNo, int gf_LogType, const char far * DebugData, int Size);
void DebugOut_textonly(const char far * gf_Filename, int gf_LineNo, int gf_LogType, const char far * DebugData, int Size);
void DebugOut_Int(const char far * gf_Filename, int gf_LineNo, int gf_LogType, int DebugData);
void DebugOut_Float(const char far * gf_Filename, int gf_LineNo, int gf_LogType, float DebugData);
void DebugOut_Hex(const char far * gf_Filename, int gf_LineNo, int gf_LogType, const unsigned char *DebugData, int Len);
int  DebugGetFileProfile(const char far * gf_Filename, int gf_LineNo);
int  DebugOutFuncTrace(const char far * gf_Filename, int gf_LineNo, int gf_LogType, const char far * DebugData, int Size);

/*****************************************************************************/
/*                           M A C R O S                                     */
/*****************************************************************************/
/* The following macros will output debug data to a file       */
/*                                                                          */

typedef enum 
{
	DEBUGLOG_FN_NORMAL,
	DEBUGLOG_FN_DEBUG2,
	DEBUGLOG_FN_DEBUG3
}DEBUGLOG_FILENAME_INDEX_;

#define DEBUGLOG_FN_DEFAULT_	DEBUGLOG_FN_NORMAL


int Debug_Str_len(const char far * );
#define DEBUGLOG_STR_(X) DebugOut(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, X, Debug_Str_len(X))
#define DEBUGLOG_INT_(X) DebugOut_Int(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, X)
#define DEBUGLOG_FLOAT_(X) DebugOut_Float(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, X)
#define DEBUGLOG_BYTES_(X,S) DebugOut(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, (const char*)X, S)
//The following macro differs from above macro in that none printable bytes are converted to hex numbers |0xFF|
#define DEBUGLOG_BYTES_TEXTONLY_(X,S) DebugOut_textonly(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, (const char*)X, S)
#define DEBUGLOG_HEX_BYTES_(X,S) DebugOut_Hex(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, (const unsigned char*)X, S)
#define DEBUGLOG_TRACE_ERROR_	DebugOut(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, NULL, -2)
#define DEBUGLOG_TRACE_	DebugOut(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, NULL, -1)


//The following macro allows a constatnt variable to be created in debug compile ONLY
//This insures that debug variables are not included in the release version
#define DEBUGLOG_STR_CONST_(VARNAME, CONST_STR)	static const char far VARNAME[] = CONST_STR
#define DEBUGLOG_VAR_(VARTYPE_, VARNAME)	static VARTYPE_ far VARNAME
#define DEBUGLOG_VAR_WITH_VALUE_(VARTYPE_, VARNAME, VALUE_)	static VARTYPE_ far VARNAME = VALUE_

#define DEBUG_BEEP(X,Z) DosBeep__(X,Z)
#define DEBUG_BEEP_BEEP DosBeep__(600, 300);DosBeep__(600, 300)
#define DEBUG_HORN DosBeep__(100, 5000)
#define DEBUG_ONLY_EVAL(EXPRESION)	EXPRESION
//The following macro should only be defined in the DEBUG version of the code.
#define REQUIRES_CHNGE_PRIOR_TO_REL_
//The purpose of the above macro is to mark code that requires modification prior to release
//Code that has the above macro, will not compile in the release version 

// The purpose of the following macro is to take a path under an if condition if
// the variable Index is set in the c:\debugenv.txt file
// In the release version of the code, this macro always returns false
#define DEBUG_GETFILEPROFILE_LN						DebugGetFileProfile(__FILE__, __LINE__)
#define DEBUG_GETFILEPROFILE_ID(ID_)				DebugGetFileProfile(__FILE__, ID_)
#define DEBUG_GETFILEPROFILE_GL(GLOBAL_NAME_, ID_)	DebugGetFileProfile(GLOBAL_NAME_, ID_)
#ifdef DEBUGLOG_TRACEALLFUNCCALLS_ON
#define DEBUGLOG_TRACE_ALL_FUNC_CALLS int DEBUG_DUMMY_VAR_4_FUNC_TRACE_ = DebugOutFuncTrace(__FILE__, __LINE__, DEBUGLOG_FN_DEFAULT_, NULL, -1)
#else
#define DEBUGLOG_TRACE_ALL_FUNC_CALLS
#endif //DEBUGLOG_TRACEALLFUNCCALLS_ON


#else /*DEBUG__MODE_*/
/* The following macros will REMOVE any debug code from the release version */
#define DEBUGLOG_STR_(X)
#define DEBUGLOG_INT_(X)
#define DEBUGLOG_FLOAT_(X)
#define DEBUGLOG_BYTES_(X,S)
#define DEBUGLOG_BYTES_TEXTONLY_(X,S)
#define DEBUGLOG_HEX_BYTES_(X,S)
#define DEBUGLOG_TRACE_ERROR_
#define DEBUGLOG_TRACE_
#define DEBUGLOG_TRACE_ALL_FUNC_CALLS

#define DEBUGLOG_STR_CONST_(VARNAME, CONST_STR)
#define DEBUGLOG_VAR_(VARTYPE_, VARNAME)
#define DEBUGLOG_VAR_WITH_VALUE_(VARTYPE_, VARNAME, VALUE_)


#define DEBUG_BEEP(X,Z)
#define DEBUG_BEEP_BEEP
#define DEBUG_HORN

#define DEBUG_ONLY_EVAL(X)
// In the release version of the code, the following macro always returns false
#define DEBUG_GETFILEPROFILE_LN						0
#define DEBUG_GETFILEPROFILE_ID(ID_)				0
#define DEBUG_GETFILEPROFILE_GL(GLOBAL_NAME_, ID_)	0

#endif /*DEBUG__MODE_*/



#endif /*!DEBUGLOG_H_HEADER_GAURD_*/
